<script>
import global from "@/views/global/global";
import axios from "axios";


export default {
  name: "Evection",
  data() {
    return {
      realName: global.user.realName,
      department:global.user.departmentName,
      travel: {
        userId: global.user.id,
        departmentId:global.user.departmentId,
        startDate:'',
        endDate:'',
        location:'',
        budget:'',
        reason:'',
        task:'',
        approverId:1,
      }
    }
  },
  methods: {
    getData() {
      if(this.travel.startDate === null || this.travel.startDate === undefined || this.travel.startDate === ''){
        this.$message({
          type: 'warning',
          message: '请输入出差日期!'
        });
        return;
      }
      if(this.travel.endDate === null || this.travel.endDate === ''){
        this.$message({
          type: 'warning',
          message: '请输入出差结束日期!'
        });
        return;
      }
      if(this.travel.location === null || this.travel.location === ''){
        this.$message({
          type: 'warning',
          message: '请输入出差地点!'
        });
        return;
      }
      if(this.travel.reason === null || this.travel.reason === undefined || this.travel.reason === ''){
        this.$message({
          type: 'warning',
          message: '请输入出差原因!'
        });
        return;
      }
      if(this.travel.task === null || this.travel.task === ''){
        this.$message({
          type: 'warning',
          message: '请输入工作任务!'
        });
        return;
      }
      if(this.travel.budget === null || this.travel.budget === ''){
        this.$message({
          type: 'warning',
          message: '请输入借款金额!'
        });
        return;
      }
      this.$confirm('确定提交吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
      axios.post("/oa/travel/addition", this.travel).then((res) => {
        console.log(res.data.result)
        if (res.data.result === "true") {
          this.$message({
            type: 'success',
            message: '提交成功!'
          });
          this.$router.push('/HomePageView')
        } else {
          this.$message({
            type: 'error',
            message: '提交失败!'
          });
        }
      })
    }).catch(
          () => {
            this.$message({
              type: 'info',
              message: '已取消'
            });
          }
      );
    },
    cancel() {
      // 返回到我的桌面
      this.$router.push('/HomePageView')
    }
    }
}
</script>

<template>
  <div  class="titleBox" >出差申请</div>

  <el-form
      label-width="auto"
      :model="book"
      style="max-width: 600px"
  >
    <el-form-item label="姓名" >
      <span>{{this.realName}}</span>
    </el-form-item>

    <el-form-item label="部门">
      <span>{{this.department}}</span>
    </el-form-item>

    <el-form-item label="出差日期" >
      <el-date-picker
                      v-model="travel.startDate"
                      type="datetime"
                      placeholder="请选择出差时间"
      />结束日期：
      <el-date-picker
                      v-model="travel.endDate"
                      type="datetime"
                      placeholder="请输入出差结束时间"
      />
    </el-form-item>

    <el-form-item label="出差地点">
      <el-input v-model="travel.location" placeholder="请输入出差的地点" />
    </el-form-item>


    <el-form-item label="出差事由">
      <el-input  type="textarea" v-model="travel.reason" placeholder="请输入出差的原因" />
    </el-form-item>

    <el-form-item label="工作任务">
      <el-input  type="textarea" v-model="travel.task" placeholder="请输入工作内容" />
    </el-form-item>

    <el-form-item label="借款金额">
      <el-input v-model="travel.budget" placeholder="请输入金额" />
    </el-form-item>

    <!--    <el-form-item label="下一步审批人">
                <el-select v-model="income.userId" placeholder="审批人" style="width: 240px">
                  &lt;!&ndash;        默认选中当前用户&ndash;&gt;
                  <el-option
                      :key="this.realName"
                      :label="this.realName"
                      :value="this.realName"
                  />
                </el-select>
              </el-form-item>-->
    <el-button type="primary" @click="getData()">确定</el-button>
    <el-button @click="cancel">取消</el-button>
  </el-form>
</template>

<style scoped lang="less">

</style>
